<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>js1.9</title>
		<link rel="stylesheet" href="css/jd.css" />
		<script src="http://g.tbcdn.cn/mtb/lib-flexible/0.3.4/??flexible_css.js,flexible.js"></script>
		<script src="https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/protocol/https/jquery/jquery-1.10.2.min_65682a2.js"></script>	
		
	</head>
	<body>
		<script>
			$(function(){
	            window.onscroll = function(){
	                if(document.body.scrollTop>100|| document.documentElement.scrollTop>100){
	                    $(".tab .top").css("position","fixed").css("top","0px");
	                }else{
	                    $(".tab .top").css("position","");		
	                }				
	                var st = document.body.scrollTop||document.documentElement.scrollTop;
	                var ch = document.body.clientHeight||document.documentElement.clientHeight;
			
	                $(".newimg").each(
	                    function(){
	                        var imgtop = $(this).offset().top;		
	                        if(imgtop>st&&imgtop<st+ch-50){
	                        	//console.log(imgtop+" "+ st+" "+ ch);
	                        	$(this).removeClass();
	                            $(this).addClass("oldimg");		                            
	                            $(this).attr("src",$(this).attr("src2"));
	                        }
	                });		
	            };
	        });
								
			
			var dataId;
			var words=["","手表 ","电器 ","零食","手机 ","烘焙"];
			var jdurl="https://img13.360buyimg.com/n7/";
			var datas;
			function jddata(data){
				 //$(".list_header").show();	
				for(var d in data){
					datas=data[d];
				}				

				$(".tab>:last-child>:nth-of-type("+(dataId)+")").html("");
	            	            								       		       
		       for(var i=0;i<datas.length;i++){		       		
		            var pro = datas[i];		            		            
		            var $newpro = $("#temp2").clone(true);
		            $newpro.find("img").attr("src2",jdurl+pro.image_url).addClass("newimg");
		            $newpro.find(".text").html(pro.ad_title);
		            $newpro.find(".prices").html("&yen;"+pro.pc_price);
		            $newpro.find(".prices2").html("&yen;"+Math.floor(pro.pc_price*1.4));
		            $newpro.show();							
		            $(".tab>:last-child>:nth-of-type("+(dataId)+")").append($newpro);
		       }		
		        document.body.scrollTop = 1;	
		       
		       
			}
					
		</script>
		<div class="d1"> 京东秒杀</div>
		<div class="tab">
			<div class="top" style="background: #fff; width: 100%;">				
				<ul class="clearfix">
					<li><p class="tophover clock">16:00</p><p class="tophover">秒杀中</p></li>
					<li><p>18:00</p><p>即将开场</p></li>
					<li><p>20:00</p><p>即将开场</p></li>
					<li><p>22:00</p><p>即将开场</p></li>
					<li><p>00:00</p><p>即将开场</p></li>
				</ul>				
			</div>	
			<div class="daojishi_tab">
				
				<!--18:00场 -->
				<div class="clearfix list_header1"  id="list_header1">
					<p class="fl p1 buy_text">秒杀中 先下单先得哦</p>
					<div class="fr mytime" id="clock1">
						<span>距结束</span>
						<span class="span1 xiaoshi" id="span1">00</span>
						<span>:</span> 
						<span class="span1 fenzhong" id="span2">00</span>
						<span>:</span>
						<span class="span1 miao" id="span3">00</span>
					</div>
				</div>
				<!--20:00场 -->
				<div class="clearfix list_header2"  id="list_header2" >
					<p class="fl p1 ">即将开场 先下单先得哦</p>
					<div class="fr mytime" id="clock1">
						<span>距开始</span>
						<span class="span1 xiaoshi2">00</span>
						<span>:</span> 
						<span class="span1 fenzhong">00</span>
						<span>:</span>
						<span class="span1 miao">00</span>
					</div>
				</div>
				
			</div>
			
			
			<div style="padding-top:30px;font-size: 28px;" id="changci">
			    <div class="time1">18:00场 </div>
			    <div class="time2">18:00场</div>
			    <div class="time3">20:00场</div>
			    <div class="time4">22:00场</div>
			    <div class="time5">00:00场</div>        
       		 </div>	
    	</div>
		
	<!--模板开始 -->
	<div class="temp clearfix" id="temp2">
		<div class="pic fl"><img src="https://ms.m.jd.com/seckill/images/defaultGoodsImage.png" /></div>
		<div class="info fl ">
			<p class="text"></p>
			<div class="price">
				<div class="fl price1">
					<p class="prices"></p>
					<p class="prices2"></p>
				</div>
				<div class="seckill fr ">
					<div class="p2 ">
						<div class="clearfix"><span class="seckill1 fr">去秒杀</span></div>
						<div class="clearfix" style="height: 20px; line-height:20px; font-size: 24px;">
							<span class="yimiao fl" style="vertical-align: middle;" id="total"></span>
							<div class="container fr">
								<div id="bar" style="width:0%;"></div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
   <!--模板结束-->
	
	
	<!--回到顶部 -->
	<div class="scroll_top" >
		<div style="width: 76px; height: 76px;">
			<img src="img/scroll-to-top-icon-new.png" style="width: 100%;" />
		</div>		
	</div>
	
		 <script>
		 	$(function(){
		 		$(".tab>:last-child>*").hide();
		 		$(".tab>:last-child>:first-child").show();
		 		
		 		$(".list_header1,.list_header2").hide();
		 		$(".list_header1").show();
		 		$(".top li").click(function(){		 			
		 			var index=$(this).index();
		 			//console.log(index);
		 			$(".top li p").removeClass();
		 			$(".top li:nth-of-type("+(index+1)+") p").addClass("tophover");
		 			$(".top li:nth-of-type("+(index+1)+") p:first-child").addClass("clock");
		 			var $current_tab = $(this).parents(".tab");
					
					$(".daojishi_tab>*").hide();
		 			$(".daojishi_tab>:nth-of-type("+(index+1)+")").show();
		 			$(".daojishi_tab>:nth-of-type(1)")
	                $current_tab.find(">:last-child>*").hide();
	                $(".buy_text").css("color","#f23030");
	                $current_tab.find(">:last-child>:nth-of-type("+(index+1)+")").show(); 
	                    
		 			loadData(index+1);
		 		});
		 		
		 		loadData(1);	
		 		
		 		
		 	});
		 	
		 	 function loadData(id){
		        dataId = id;
		        $(".jdscript").remove();
		        var jdscript = document.createElement("script");
		        jdscript.src="https://x.jd.com/Search?callback=jddata&area=1&enc=utf-8&keyword="+words[id]
		            +"&adType=7&page=2&ad_ids=291%3A33&xtest=new_search&_=1516261707892";
		        jdscript.className = "jdscript";
		       document.body.appendChild(jdscript);
		   }
		 			 			 	
			/*进度条*/
			
			
			var a = Math.floor(Math.random()*100);
			console.log(a);

			function run() {
				var bar = document.getElementById("bar");
				var total = document.getElementById("total");
				bar.style.width = parseInt(bar.style.width) + 1 + "%";
				total.innerHTML ="已秒"+ bar.style.width;
				if(bar.style.width == a + "%") {
					window.clearTimeout(timeout);
					return;
				}
				var timeout = window.setTimeout("run()", 40);
			}
			window.onload = function() {
				run();
			}	
			
			
			
			
			var timer=setInterval(function(){
				
			var today=new Date();
			var n=today.getFullYear();
			var y=today.getMonth()+1;
			var r=today.getDate();
			var h=today.getHours();
			var f=today.getMinutes();
			var m=today.getSeconds();
			var now=new Date();
			var end=new Date(n,y,r,18,00);
			var end1=new Date(n,y,r,20,00);
			var shengyu=end.getTime()-now.getTime();
			var shengyu2=end1.getTime()-now.getTime();
			
			var xiaoshi=Math.floor(shengyu/(1000*60*60)%24);
			var xiaoshi2=Math.floor(shengyu2/(1000*60*60)%24);
			var fenzhong=Math.floor(shengyu/(1000*60)%60);
			var miao=Math.floor(shengyu/(1000)%60);
			
			$(".xiaoshi").html(xiaoshi<10?"0"+xiaoshi:xiaoshi);
			$(".fenzhong").html(fenzhong<10?"0"+fenzhong:fenzhong);
			$(".miao").html(miao<10?"0"+miao:miao);
			
			
			
			
		},1000);
		 </script>
	</body>
	
</html>
